<template>
  <div class="dashboard-container">
    <!-- 数据卡片 -->
    <el-row class="mb-10">
      <el-col :span="18" :offset="3">
        <el-input
          v-model="search.url"
          placeholder="输入地址搜索"
          clearable
          size="large"
          :prefix-icon="Search"
          @change="getImageUrl()"
        >
          <template #append>
            <el-button type="primary" @click="getImageUrl()">搜索</el-button>
          </template>
        </el-input>
      </el-col>
    </el-row>
    <el-row class="mt-3" v-if="imageUrlList.length">
      <el-col :span="24">
        <div v-if="imageUrlList1.length" class="card-title mb fw-700 bg-amber">
          常用
        </div>
        <div class="card-item">
          <div
            v-for="item in imageUrlList1"
            :key="item.id"
            class="card-item__content bg-gradient-from-amber bg-gradient-to-r"
            @click="handleClick(item)"
          >
            <img :src="item.logo_url" alt="" />
            <el-tooltip
              class="box-item"
              effect="dark"
              :content="item.url"
              placement="bottom"
            >
              <div>
                <div>{{ item.name }}</div>
                <div class="fw-400 c-gray">{{ item.url }}</div>
              </div>
            </el-tooltip>
          </div>
        </div>

        <div v-if="imageUrlList2.length" class="card-title mb fw-400 bg-blue">
          其他
        </div>
        <div class="card-item">
          <div
            v-for="item in imageUrlList2"
            :key="item.id"
            class="card-item__content bg-gradient-from-blue bg-gradient-to-r"
            @click="handleClick(item)"
          >
            <img :src="item.logo_url" alt="" />
            <el-tooltip
              class="box-item"
              effect="dark"
              :content="item.url"
              placement="bottom"
            >
              <div>
                <div>{{ item.name }}</div>
                <div class="fw-400 c-gray">{{ item.url }}</div>
              </div>
            </el-tooltip>
          </div>
        </div>

        <!-- 新增 -->
        <div v-if="imageUrlList3.length" class="card-title mb fw-700 bg-sky">
          业务系统
        </div>
        <div class="card-item">
          <div
            v-for="item in imageUrlList3"
            :key="item.id"
            class="card-item__content bg-gradient-from-cyan bg-gradient-to-r"
            @click="handleClick(item)"
          >
            <img :src="item.logo_url" alt="" />
            <el-tooltip
              class="box-item"
              effect="dark"
              :content="item.url"
              placement="bottom"
            >
              <div>
                <div>{{ item.name }}</div>
                <div class="fw-400 c-gray">{{ item.url }}</div>
              </div>
            </el-tooltip>
          </div>
        </div>
        <!-- 新增 -->
      </el-col>
    </el-row>

    <div v-else>暂无数据</div>

    <el-dialog
      v-model="dialogVisible"
      title="账号信息"
      width="40%"
      :before-close="handleClose"
      draggable
    >
      <el-descriptions class="margin-top" :column="2" :size="size" border>
        <el-descriptions-item>
          <template #label>
            <div class="cell-item">
              <el-icon :style="iconStyle">
                <user />
              </el-icon>
              <span>名称</span>
            </div>
          </template>
          {{ dialogInfo.name }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template #label>
            <div class="cell-item">
              <el-icon :style="iconStyle">
                <Connection />
              </el-icon>
              <span>分类</span>
            </div>
          </template>
          {{ dialogInfo.category }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template #label>
            <div class="cell-item">
              <el-icon :style="iconStyle">
                <user />
              </el-icon>
              <span>用户名</span>
            </div>
          </template>
          {{ dialogInfo.username }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template #label>
            <div class="cell-item">
              <el-icon :style="iconStyle">
                <iphone />
              </el-icon>
              <span>手机号</span>
            </div>
          </template>
          {{ dialogInfo.phone }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template #label>
            <div
              class="cell-item cursor-pointer"
              @click="showPassword = !showPassword"
            >
              <el-icon :style="iconStyle">
                <View />
              </el-icon>
              <span>密码</span>
            </div>
          </template>
          <span v-if="showPassword">{{ dialogInfo.password }}</span>
          <span v-else>******</span>
        </el-descriptions-item>
        <el-descriptions-item>
          <template #label>
            <div class="cell-item">
              <el-icon :style="iconStyle">
                <office-building />
              </el-icon>
              <span>地址</span>
            </div>
          </template>
          {{ dialogInfo.url }}
        </el-descriptions-item>
      </el-descriptions>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="dialogVisible = false"
            >取消</el-button
          >
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
defineOptions({
  name: "Dashboard",
  inheritAttrs: false,
});

import HomeAPI from "@/api/home/index";
import { IImageUrlPageVO } from "@/api/home/model";
import { Calendar, Search } from "@element-plus/icons-vue";

const imageUrlList = ref<IImageUrlPageVO[]>([]);
const imageUrlList1 = ref<IImageUrlPageVO[]>([]);
const imageUrlList2 = ref<IImageUrlPageVO[]>([]);
const imageUrlList3 = ref<IImageUrlPageVO[]>([]);
const dialogVisible = ref(false);
const dialogInfo = ref<IImageUrlPageVO>();
const showPassword = ref(false);
const search = reactive({
  url: "",
});
function getImageUrl() {
  const datas = {
    ...search,
  };
  HomeAPI.getImageUrl(datas).then((res) => {
    imageUrlList.value = res.data as any;
    imageUrlList1.value = res.data.filter(
      (item: IImageUrlPageVO) => item.category === "常用"
    );
    imageUrlList2.value = res.data.filter(
      (item: IImageUrlPageVO) => item.category === "其他"
    );
    imageUrlList3.value = res.data.filter(
      (item: IImageUrlPageVO) => item.category === "业务系统"
    );
  });
}

function handleClick(item: IImageUrlPageVO) {
  dialogVisible.value = true;
  dialogInfo.value = item;
  window.open(dialogInfo.value?.url);
}

function handleClose(done: () => void) {
  dialogVisible.value = false;
}

onMounted(() => {
  getImageUrl();
});
</script>

<style lang="scss" scoped>
.dashboard-container {
  position: relative;
  min-height: calc(-84px + 100vh);
  padding: 24px;
  background-color: rgb(60 58 58 / 0%);

  .user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
  }

  .github-corner {
    position: absolute;
    top: 0;
    right: 0;
    z-index: 1;
    border: 0;
  }

  .data-box {
    display: flex;
    justify-content: space-between;
    padding: 20px;
    font-weight: bold;
    color: var(--el-text-color-regular);
    background: var(--el-bg-color-overlay);
    border-color: var(--el-border-color);
    box-shadow: var(--el-box-shadow-dark);
  }

  .svg-icon {
    fill: currentcolor !important;
  }

  :deep(.el-input-group__append),
  :deep(.el-input-group__prepend) {
    color: #fff;
    background-color: var(--el-color-primary);
    border: 0 5px 5px 0;
  }

  :deep(.el-input) {
    height: 40px;
  }
}

.card-title {
  width: 100%;
  padding: 5px;
  border-radius: 5px;
}

.card-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  width: 100%;

  .card-item__content {
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 19%;
    padding: 15px;
    margin-right: 17px;
    margin-bottom: 10px;
    cursor: pointer;
    border: 1px solid #ccc;
    border-radius: 5px;

    &:hover {
      box-shadow: 0 5px 10px #ccc;
      animation: moveCard 0.6s forwards ease-in;
    }

    img {
      width: 40px;
      margin-right: 10px;
    }
  }

  .card-item__content:nth-child(5n) {
    margin-right: 0;
  }
}

.margin-top {
  .cell-item {
    display: flex;
    align-items: center;
  }
}

@keyframes moveCard {
  0% {
    transform: translateY(0);
  }

  100% {
    transform: translateY(-10px);
  }
}
</style>

<style lang="scss"></style>
